package org.groupg.practice.configuration.validator;

import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ex.ConfigurationException;

public class Main {
    public static void main(String[] args) {
        ValidatingConfigurationLoader loader = new ValidatingConfigurationLoader();

        // 添加文件路径校验器
        loader.addValidator(new FilePathValidator("data.file"));
        loader.addValidator(new FilePathValidator("log.dir"));

// 使用：当 data.file 缺失时，设置为默认路径
        loader.addValidator(new DefaultValueValidator("data.file", "/default/data.csv"));

        try {
            Configuration config = loader.loadConfig("app.properties");
            System.out.println("配置加载成功！");
        } catch (ConfigurationException e) {
            System.err.println("配置校验失败: " + e.getMessage());
        }
    }
}
